// fast4j - Fast & Agile Service Tools for Java
// Copyright (C) 2007 Alexandre ROMAN
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

// $Id: EchoServiceImpl.java 36 2007-03-27 22:02:40Z alexandre.roman $

package service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import service.api.EchoService;
import service.api.ServiceContext;
import service.api.ServiceContextHolder;

/**
 * {@link EchoService} implementation.
 * @author alexandre.roman
 */
public class EchoServiceImpl implements EchoService {
    private final Logger log = LoggerFactory.getLogger(getClass());
    
    public String echo(String str) {
        final ServiceContext ctx = ServiceContextHolder.get();
        
        if (str == null) {
            // the client will get this message + an exception
            ctx.getMessages().add("I don't like null values");
            throw new IllegalArgumentException("Value for 'str' cannot be null");
        }
        log.info("Return same string: {}", str);
        
        // we are returning more than just a single value: the client
        // will also get this message
        ctx.getMessages().add("Hello from EchoService");
        
        return str;
    }
}
